package com.gyf.usercenter.ui.presenter

import com.gyf.base.ext.execute
import com.gyf.base.presenter.BasePresenter
import com.gyf.base.rx.BaseSubscriber
import com.gyf.usercenter.data.protocol.UserInfo
import com.gyf.usercenter.service.UserService
import com.gyf.usercenter.service.lmpl.UserServiceImpl
import com.gyf.usercenter.ui.presenter.view.LoginView
import com.gyf.usercenter.ui.presenter.view.RegisterView
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

class LoginPresenter @Inject constructor() : BasePresenter<LoginView>() {
    @Inject
    lateinit var userService: UserService

    fun login(mobile: String, pwd: String, pushId: String) {
        if (!checkNetWork()) {
            return;
        }
        mView.showLoading();
        userService.login(mobile, pwd, pushId)
                .execute(object : BaseSubscriber<UserInfo>(mView) {
                    override fun onNext(t: UserInfo?) {
                        super.onNext(t);
                        mView.onLoginResult(t);
                    }
                }, lifecycleProvider);
    }
}